package com.amigo.online.consumer.user.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.amigo.online.common.base.controller.BaseConsumerController;
import com.amigo.online.common.core.response.Response;
import com.amigo.online.common.param.dto.login.ExistDto;
import com.amigo.online.common.param.dto.login.LoginByIdDto;
import com.amigo.online.common.param.dto.login.LoginDto;
import com.amigo.online.common.param.dto.login.RegisterDto;
import com.amigo.online.consumer.user.service.LoginService;



/**
 * 登录相关
 * @author amigo
 *
 */

@RestController
@RequestMapping(value = "", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public class LoginController extends BaseConsumerController {
	
	@Autowired
	LoginService loginService;

	@PostMapping(value = "/user/login")
	public ResponseEntity<Response> login(HttpServletRequest request) {
        LoginDto loginDto = (LoginDto) getDto(request, LoginDto.class);
        return loginService.login(loginDto);
    }
	
	@PostMapping(value = "/user/register")
	public ResponseEntity<Response> resiter(HttpServletRequest request) {
		RegisterDto dto = (RegisterDto)getDto(request,RegisterDto.class);
		return loginService.register(dto);
    }
	
	@PostMapping(value = "/user/exist")
	public ResponseEntity<Response> exist(HttpServletRequest request) {
		ExistDto dto = (ExistDto)getDto(request,ExistDto.class);
		return loginService.exist(dto);
    }
	
	@PostMapping(value = "/user/loginById")
	public ResponseEntity<Response> loginById(HttpServletRequest request) {
		LoginByIdDto dto = (LoginByIdDto) getDto(request,LoginByIdDto.class);
		return loginService.loginById(dto);
    }
}
